#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
	int a = 0, b = 0;
	scanf("%d %d", &a, &b);
	if (a < b)
	{
		int temp = a;
		a = b;
		b = temp;
	}
	int c = 0;
	while (1)
	{
		c = a % b;
		if (b == 0)
		{
			break;
		}
		a = b;
		b = c;
	}
	printf("%d\n", b);
	return 0;
}